package org.example.code.test2025.two_month;

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        long[] lNums = new long[t];
        long[] rNums = new long[t];
        long[] re = new long[t];
        int index = 0;
        while(t>0){
            long n = in.nextLong();
            long l = in.nextLong();
            long r = in.nextLong();
            boolean f = false;
            for(int i=0;i<index;i++){
                if(l>=lNums[i]&&r<=rNums[i]){
                    System.out.println(re[i]);
                    f = true;
                    t--;
                    break;
                }
            }
            if(f){
                continue;
            }
            lNums[index] = l;
            rNums[index] = r;
            long te = fun(n,l,r);
            re[index] = te;
            System.out.println(te);
            t--;
            index++;
        }
    }

    public static long fun(long n,long l,long r){
        long max = Long.MIN_VALUE;
        for(long i=l;i<=r;i++){
            long t = n^i;
            max = Math.max(t,max);
        }
        return max;
    }
}
